#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
    vector<vector<int>> fourSum(vector<int>& nums ,int target) {
        vector<vector<int>> ans;
        if (nums.size() < 4)return ans;
        sort(nums.begin(), nums.end());
        for (int k = 0; k < nums.size() - 3; k++)
        {
            if (k > 0 && nums[k] == nums[k - 1])continue;
            for (int i = k + 1; i < nums.size() - 2; i++)
            {
                if (i > k + 1 && nums[i] == nums[i - 1])continue;
                int z = i + 1, y = nums.size() - 1;
                while (z < y)
                {
                    //cout << nums[i] << " " << nums[z] << " " << nums[y] << endl;
                    if (nums[k] + nums[i] + nums[z] + nums[y] == target)
                    {
                        vector<int> temp;
                        temp.push_back(nums[k]);
                        temp.push_back(nums[i]);
                        temp.push_back(nums[z]);
                        temp.push_back(nums[y]);
                        ans.push_back(temp);
                    }
                    if (nums[k] + nums[i] + nums[z] + nums[y] > target)
                    {
                        while (z < y && nums[y] == nums[y - 1])y--;
                        y--;
                    }
                    else
                    {
                        while (z < y && nums[z] == nums[z + 1])z++;
                        z++;
                    }
                }

            }
        }
        return ans;
    }
};
int main()
{
    vector<int> nums = { 0,0,0,0};
    Solution sol;
    vector<vector<int>> ans = sol.fourSum(nums,0);
    for (int i = 0; i < ans.size(); i++)
    {
        for (int j = 0; j < ans[i].size(); j++)
        {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}